<template>
  <div class="hollow-text-page">
    <div class="hollow-text-container">
      <h1>空心文本生成器</h1>
      
      <el-form @submit.prevent="generateHollowText">
        <el-form-item>
          <el-input 
            v-model="inputText" 
            placeholder="请输入要转换的文本"
            type="text"
            clearable>
          </el-input>
        </el-form-item>
        
        <el-form-item>
          <el-button type="primary" native-type="submit">
            <el-icon><MagicStick /></el-icon>
            生成
          </el-button>
        </el-form-item>
      </el-form>

      <div v-if="hollowText" class="result">
        <p class="tips">生成结果：</p>
        <div class="hollow-text">{{ hollowText }}</div>
        <el-button type="success" @click="copyHollowText">
          <el-icon><CopyDocument /></el-icon>
          复制
        </el-button>
      </div>

      <div class="button-group">
        <el-button type="warning" @click="returnToHome">
          <el-icon><Back /></el-icon>
          返回首页
        </el-button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { MagicStick, CopyDocument, Back } from '@element-plus/icons-vue'
import { copyText } from '@/utils/clipboard'

const router = useRouter()
const inputText = ref('xiyueta.com')
const hollowText = ref('')

// 空心字符映射表
const hollowChars = {
  'A': '𝔸', 'B': '𝔹', 'C': 'ℂ', 'D': '𝔻', 'E': '𝔼', 'F': '𝔽', 'G': '𝔾', 'H': 'ℍ', 'I': '𝕀', 'J': '𝕁',
  'K': '𝕂', 'L': '𝕃', 'M': '𝕄', 'N': 'ℕ', 'O': '𝕆', 'P': 'ℙ', 'Q': 'ℚ', 'R': 'ℝ', 'S': '𝕊', 'T': '𝕋',
  'U': '𝕌', 'V': '𝕍', 'W': '𝕎', 'X': '𝕏', 'Y': '𝕐', 'Z': 'ℤ',
  'a': '𝕒', 'b': '𝕓', 'c': '𝕔', 'd': '𝕕', 'e': '𝕖', 'f': '𝕗', 'g': '𝕘', 'h': '𝕙', 'i': '𝕚', 'j': '𝕛',
  'k': '𝕜', 'l': '𝕝', 'm': '𝕞', 'n': '𝕟', 'o': '𝕠', 'p': '𝕡', 'q': '𝕢', 'r': '𝕣', 's': '𝕤', 't': '𝕥',
  'u': '𝕦', 'v': '𝕧', 'w': '𝕨', 'x': '𝕩', 'y': '𝕪', 'z': '𝕫',
  '0': '𝟘', '1': '𝟙', '2': '𝟚', '3': '𝟛', '4': '𝟜', '5': '𝟝', '6': '𝟞', '7': '𝟟', '8': '𝟠', '9': '𝟡'
}

const generateHollowText = () => {
  if (!inputText.value) return
  
  // 转换文本为空心字符
  hollowText.value = inputText.value
    .split('')
    .map(char => hollowChars[char] || char)  // 如果字符不在映射表中，保持原字符
    .join('')
}

const copyHollowText = () => {
  if (hollowText.value) {
    copyText(hollowText.value)
  }
}

const returnToHome = () => {
  router.push('/')
}
</script>

<style lang="scss" scoped>
.hollow-text-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 20px;
  box-sizing: border-box;
  display: flex;
  justify-content: center;
  align-items: center;

  .hollow-text-container {
    max-width: 600px;
    width: 96%;
    background-color: rgba(255, 255, 255, 0.95);
    border-radius: 20px;
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.2);
    padding: 30px;
    box-sizing: border-box;
    margin: 20px auto;

    h1 {
      text-align: center;
      color: #4a5568;
      font-size: 28px;
      margin-bottom: 30px;
      text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
    }

    .el-form {
      margin-bottom: 30px;

      .el-button {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        padding: 12px 20px;
        font-size: 16px;
      }
    }

    .result {
      margin: 20px 0;
      padding: 20px;
      background-color: #f0f9eb;
      border: 1px solid #e1f3d8;
      border-radius: 12px;
      text-align: center;

      .tips {
        color: #67c23a;
        font-weight: bold;
        margin-bottom: 15px;
      }

      .hollow-text {
        padding: 15px;
        background: white;
        border-radius: 8px;
        font-size: 18px;
        margin-bottom: 15px;
        word-break: break-all;
        box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.06);
      }

      .el-button {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
      }
    }

    .button-group {
      margin-top: 30px;
      display: flex;
      justify-content: center;

      .el-button {
        min-width: 120px;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
      }
    }
  }
}

@media (max-width: 480px) {
  .hollow-text-page {
    padding: 10px;

    .hollow-text-container {
      padding: 20px;

      h1 {
        font-size: 24px;
      }
    }
  }
}
</style>
